#define  _CRT_SECURE_NO_WARNINGS
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int prime(int n)
{
	if (n % 3 == 0)
		return 0;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return 0;
	}
	return n;
}
int main()
{
	int a = 0;
	int b = 0;
	scanf("%d%d", &a, &b);
	int i = 5;
	int n1 = 0;
	int n2 = 0;
	int n3 = 0;
	int n4 = 0;
	int n5 = 0;
	for (n3 = 1; n3 <= 9; n3 += 2)
	{
		int num = n3;
		if (num >= a && num <= b)
		{
			if (prime(num) != 0)
				printf("%d\n", num);
		}
	}
	if (b < 10)
		return 0;
	for (n3 = 1; n3 <= 9; n3 += 2)
	{
		int num = n3 + n3 * 10;
		if (num >= a && num <= b)
		{
			if (prime(num) != 0)
				printf("%d\n", num);
		}
	}
	if (b < 100)
		return 0;
	for (n2 = 1; n2 <= 9; n2 += 2)
	{
		for (n3 = 0; n3 <= 9; n3++)
		{
			int num = n2 * 100 + n2 + n3 * 10;
			if (num >= a && num <= b)
			{
				if (prime(num) != 0)
					printf("%d\n", num);
			}
		}
	}
	if (b < 1000)
		return 0;
	for (n2 = 1; n2 <= 9; n2 += 2)
	{
		for (n3 = 0; n3 <= 9; n3++)
		{
			int num = n2 * 1000 + n2 + n3 * 10 + n3 * 100;
			if (num >= a && num <= b)
			{
				if (prime(num) != 0)
					printf("%d\n", num);
			}
		}
	}
	if (b < 10000)
		return 0;
	for (n1 = 1; n1 <= 9; n1 += 2)
	{
		for (n2 = 0; n2 <= 9; n2++)
		{
			for (n3 = 0; n3 <= 9; n3++)
			{
				int num = n1 * 10000 + n1 + n2 * 1000 + n2 * 10 + n3 * 100;
				if (num >= a && num <= b)
				{
					if (prime(num) != 0)
						printf("%d\n", num);
				}
			}
		}
	}
	if (b < 100000)
		return 0;
	for (n1 = 1; n1 <= 9; n1 += 2)
	{
		for (n2 = 0; n2 <= 9; n2++)
		{
			for (n3 = 0; n3 <= 9; n3++)
			{
				int num = n1 * 100000 + n1 + n2 * 10000 + n2 * 10 + n3 * 100 + n3 * 1000;
				if (num >= a && num <= b)
				{
					if (prime(num) != 0)
						printf("%d\n", num);
				}
			}
		}
	}
	if (b < 1000000)
		return 0;
	for (n1 = 1; n1 <= 9; n1 += 2)
	{
		for (n2 = 0; n2 <= 9; n2++)
		{
			for (n3 = 0; n3 <= 9; n3++)
			{
				for (n4 = 0; n4 <= 9; n4++)
				{
					int num = n1 * 1000000 + n1 + n2 * 100000 + n2 * 10 + n3 * 100 + n3 * 10000 + n4 * 1000;
					if (num >= a && num <= b)
					{
						if (prime(num) != 0)
							printf("%d\n", num);
					}
				}
			}
		}
	}
	if (b < 10000000)
		return 0;
	for (n1 = 1; n1 <= 9; n1 += 2)
	{
		for (n2 = 0; n2 <= 9; n2++)
		{
			for (n3 = 0; n3 <= 9; n3++)
			{
				for (n4 = 0; n4 <= 9; n4++)
				{
					int num = n1 * 10000000 + n1 + n2 * 1000000 + n2 * 10 + n3 * 100 + n3 * 100000 + n4 * 10000 + n4 * 1000;
					if (num >= a && num <= b)
					{
						if (prime(num) != 0)
							printf("%d\n", num);
					}
				}
			}
		}
	}
	if (b < 100000000)
		return 0;
	for (n1 = 1; n1 <= 9; n1 += 2)
	{
		for (n2 = 0; n2 <= 9; n2++)
		{
			for (n3 = 0; n3 <= 9; n3++)
			{
				for (n4 = 0; n4 <= 9; n4++)
				{
					for (n5 = 0; n5 <= 9; n5++)
					{
						int num = n1 * 100000000 + n1 + n2 * 10000000 + n2 * 10 + n3 * 100 + n3 * 1000000 + n4 * 100000 + n4 * 1000 + n5 * 10000;
						if (num >= a && num <= b)
						{
							if (prime(num) != 0)
								printf("%d\n", num);
						}
					}
				}
			}
		}
	}
	return 0;
}